import { _decorator, Component, find, instantiate, Node, Sprite, SpriteFrame, } from 'cc';
import { WsMgr } from '../TCP/WsMgr';
import { AbsAdapter, ListView } from '../Common/ListView';
import { GameListAdapter } from './GameListAdapter';
import { Utils } from '../Common/Utils';

const { ccclass, property } = _decorator;

@ccclass('GameList')
export class GameList extends Component {

    @property(Node)
    private GameList:Node;
   
    @property(ListView)
    private scoreRankListView:ListView;

    private _scoreRankListAdapter: GameListAdapter | null = null;
  
    getscoreRankListAdapter(): GameListAdapter {
    if (!this._scoreRankListAdapter) {
        this._scoreRankListAdapter = new GameListAdapter();
      }
      return this._scoreRankListAdapter;
    }    

   

    start() {
        console.log('GameList start');
       
    }

    update(deltaTime: number) {
        
    }

    onLoad() {
       // let gameList:Array<GameResult>= new Array<GameResult>;
        // for(let i=0;i<100;i++)
        // {
        //   let itemData:GameResult = new GameResult();
        //   itemData.orderid = 1000+i+'';
        //   itemData.fee= 1000;
        //   itemData.prize = 1950;
        //   itemData.item = 1;
        //   gameList[i] = itemData;  
        // }

        const raw=WsMgr.getInstance().getGameList();
        let gameList=Utils.deepCopy(raw).reverse();
        this.getscoreRankListAdapter().setDataSet(gameList);
        this.scoreRankListView.setAdapter(this._scoreRankListAdapter);
       
    }

    updateGameList(){
        let raw=WsMgr.getInstance().getGameList();
        let gameList=Utils.deepCopy(raw).reverse();
        this.getscoreRankListAdapter().setDataSet(gameList);
        console.log('GameList=',gameList);
        this.scoreRankListView.setAdapter(this._scoreRankListAdapter);
    }

    onClose(){
        this.GameList.active=false;
    }
    
   

    
}


